//
//  Dealer.m
//  blackjack
//
//  Created by kyocooro on 4/1/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Dealer.h"
#import <QuartzCore/QuartzCore.h>
#import "EpImageProcessor.h"
#import "constants.h"
@interface Dealer(Private)
UIImageView *deck_;
UIImageView *player1_;
UIImageView *translation_;
- (UIImage *)getCard:(int)no andType:(int)type;


@end

@implementation Dealer


- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
		[self setUserInteractionEnabled:YES];
		UIImage *bg = [UIImage imageNamed:@"dealerbg.png"];
		[self setImage:bg];
		
		
		UIButton *dealButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
		[dealButton setFrame:CGRectMake(250, 240, 20, 40)];
		[dealButton	setTitle:@"deal" forState:UIControlStateNormal];
		[dealButton addTarget:self action:@selector(dealCardTo) forControlEvents:UIControlEventTouchUpInside];
		[self addSubview:dealButton];
		
		deck_ = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 73, 98)];
		[deck_ setImage:[UIImage imageNamed:@"PlayCard1AL.png"]];
		[self addSubview:deck_];
		
		player1_ = [[UIImageView alloc] initWithFrame:CGRectMake(200, 100, 73, 98)];
		[self addSubview:player1_];
		
		translation_ = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 73, 98)];
		[translation_ setImage:[UIImage imageNamed:@"PlayCard1AL.png"]];
		[self addSubview:translation_];
		
    }
    return self;
}
		
- (UIImage *)getCard:(int)no andType:(int)type
{
	UIImage *deck = [UIImage imageNamed:@"classic-playing-cards.png"];
	CGRect cardRect = CGRectMake((no - 1) * 73, type * 98, 72, 98);
	return [EpImageProcessor createSubImage:deck withRect:cardRect];
}
- (void)dealCardTo
{
	
	//CABasicAnimation *translationX;	
//	translationX=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
//	translationX.duration=.5;
//	translationX.repeatCount=1;
//	translationX.fillMode = kCAFillModeBoth;
//	translationX.fromValue=[NSNumber numberWithFloat:translation_.frame.origin.x];
//	translationX.toValue=[NSNumber numberWithFloat:200];
//	
//	CABasicAnimation *translationY;
//	translationY=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
//	translationY.duration=.5;
//	translationY.repeatCount=1;
//	translationY.fillMode = kCAFillModeBoth;
//	translationY.fromValue=[NSNumber numberWithFloat:translation_.frame.origin.y];
//	translationY.toValue=[NSNumber numberWithFloat:100];
//	
//	CAAnimationGroup *theGroup = [CAAnimationGroup animation];
//	theGroup.delegate = self;
//	theGroup.duration = .5;
//	theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
//	theGroup.animations = [NSArray arrayWithObjects:translationX, translationY, nil];
//	[translation_.layer addAnimation:theGroup forKey:@"animateLayer"];
//	translation_.center = player1_.center;
//	translation_.transform = CGAffineTransformIdentity;
	//CGRect frame = translation_.frame;
//	frame.origin.y = 200; // final y destination
//	
//	[UIView beginAnimations:@"someName" context:nil];
//	[UIView setAnimationDuration:1];
//	translation_.transform = CGAffineTransformMakeRotation(M_PI_2);
//	[UIView commitAnimations];
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
	//[player1_ setImage:[self getCard:7 andType:HEART]];
}

- (void)drawRect:(CGRect)rect {
    // Drawing code
}


- (void)dealloc {
    [super dealloc];
}


@end
